#include <map>
#include <string>
#include <iostream>
#include "structured_binding.h"

void CStructuredBinding::mapInsert()
{
    std::map<std::string, int> cities;
    cities["beijing"] = 0;
    cities["shanghai"] = 1;
    cities["shenzhen"] = 2;
    cities["guangzhou"] = 3;

#if 0

    for (const auto& [key, value] : cities) {
        std::cout << key << " : " << value << std::endl;
    }

#endif

    //std::pair<std::map<std::string, int>::iterator, bool> result = cities.insert(std::pair<std::string, int>("shanghai", 4));
    //auto result = cities.insert(std::pair<std::string, int>("shanghai", 4));
    auto result = cities.insert(std::make_pair("beijing", 4));
    std::cout << "is insertion success? " << (result.second ? "true" : "false")
              << ", element key:" << result.first->first << ", value:" << result.first->second
              << std::endl;

#if 0
    auto [iterator, inserted] = cities.insert(std::make_pair("nanjing", 4));
    std::cout << "is insertion success? " << (inserted ? "true" : "false")
              << ", element key:" << iterator->first << ", value:" << iterator->second
              << std::endl;
#endif
}

void CStructuredBinding::tupleLearn()
{
    std::tuple<std::string, std::string, int, int, std::string> userInfo("Tom", "123456", 0, 25, "Pudong Street");
    std::string userName = std::get<0>(userInfo);
    std::string passWord = std::get<1>(userInfo);
    int gender = std::get<2>(userInfo);
    int age = std::get<3>(userInfo);
    std::string address = std::get<4>(userInfo);

    std::cout << userName << ", " << passWord << ", " << gender << ", " << age << ", " << address << std::endl;
}